#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;

vector<int> nex[maxn];
vector<int> leaf;

void dfs(int u, int fa){
    if(nex[u].size() == 1) leaf.push_back(u);
    else
        for (int i = 0; i < nex[u].size(); ++i) {
            if(nex[u][i] != fa) dfs(nex[u][i], u);
        }
}

int main(){
    int n; cin >> n;
    for (int i = 1; i <= n-1; ++i) {
        int a, b;
        cin >> a >> b;
        nex[a].push_back(b);
        nex[b].push_back(a);
    }

    if(n == 1) cout  << "0\n";
    else if(n == 2) cout << "1\n1 2";
    else{
        int root;
        for (int i = 1; i <= n; ++i) {
            if(nex[i].size() > 1) {root = i; break;}
        }
        dfs(root, root);
        int m = leaf.size();
        int mid = (m+1)/2;
        cout << mid << "\n";
        for (int i = 0; i < leaf.size()/2; ++i) {
            cout << leaf[i] << " " << leaf[i+mid] << "\n";
        }
        if(m%2) cout << leaf[mid-1] << " " << root;
    }
    return 0;
}
